package com.ymatou.iapi.productmanager.testcase.old202012;

import com.ymatou.iapi.productmanager.parameter.QueryAlhProductsBean;
import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymatou.iapi.productmanager.service.QueryAlhProductsCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P2;
import com.ymttest.business.service.ProductManagerCallServiceV2;
import com.ymttest.business.service.ProductManagerCallServiceV3;
import com.ymttest.utils.EnvSetup;
import org.junit.*;
import org.junit.experimental.categories.Category;
/**
*查询安利会推广中的商品列表
*FreeMaker Template自动生成代码
*/
@TestSuite
@Ignore
public class Ts_QueryAlhProducts{
	private static QueryAlhProductsBean queryalhproductsBean;
	private static QueryAlhProductsCall queryalhproductsCall;
	private static int sellerId = Integer.parseInt(EnvSetup.getData("productsellerid"));
	private static String sellerName = EnvSetup.getData("productsellername");
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询安利会推广中的商品列表（忽略20210107 接口废弃）");
	}

	@Before
	public void caseUp() {
		queryalhproductsBean=new QueryAlhProductsBean();
		queryalhproductsCall=new QueryAlhProductsCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(queryalhproductsCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_QueryAlhSelectionProducts_001() {
		Logger.start(true, "根据买手id进行查询,查询成功");
		try {

			queryalhproductsBean.setUserId(sellerId);
			queryalhproductsBean.setPageIndex(1);
			queryalhproductsBean.setPageSize(100);
			
			
			queryalhproductsCall.setData(queryalhproductsBean);
			queryalhproductsCall.callService();
			Logger.verifyEquals("200", queryalhproductsCall.getJsonObject().get("Code").getAsString(), "验证Code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_QueryAlhSelectionProducts_002() {
		Logger.start(true, "根据买手id与商品名称进行查询,查询成功");
		try {
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV3.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject()
					.get("ProductId").getAsString();
			
			Thread.sleep(5000);
			ProductManagerCallServiceV3.BatchAddAlhProduct(sellerId, productId);
			Thread.sleep(5000);
			queryalhproductsBean.setUserId(sellerId);
			queryalhproductsBean.setTitle(addProdReq.getProduct().getProductName());
			queryalhproductsBean.setPageIndex(1);
			queryalhproductsBean.setPageSize(100);
			
			queryalhproductsCall.setData(queryalhproductsBean);
			queryalhproductsCall.callService();
			Logger.verifyEquals("200", queryalhproductsCall.getJsonObject().get("Code").getAsString(), "验证Code");
			Logger.verifyNotEquals(-1, queryalhproductsCall.getJsonObject().toString().indexOf(productId), "查询结果是否包含此商品");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_QueryAlhSelectionProducts_003() {
		Logger.start(true, "根据买手id、二级类目id进行查询,查询成功");
		try {
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV3.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject()
					.get("ProductId").getAsString();
			Thread.sleep(5000);
			ProductManagerCallServiceV3.BatchAddAlhProduct(sellerId, productId);
			Thread.sleep(5000);
			queryalhproductsBean.setUserId(sellerId);
			queryalhproductsBean.setSecondCategoryId(addProdReq.getProduct().getSecondCategoryId());
			queryalhproductsBean.setPageIndex(1);
			queryalhproductsBean.setPageSize(100);
			
			queryalhproductsCall.setData(queryalhproductsBean);
			queryalhproductsCall.callService();
			Logger.verifyEquals("200", queryalhproductsCall.getJsonObject().get("Code").getAsString(), "验证Code");
			Logger.verifyNotEquals(-1, queryalhproductsCall.getJsonObject().toString().indexOf(productId), "查询结果是否包含此商品");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_QueryAlhSelectionProducts_004() {
		Logger.start(true, "根据买手id、品牌进行查询,查询成功");
		try {
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV3.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject()
					.get("ProductId").getAsString();
			Thread.sleep(5000);
			ProductManagerCallServiceV3.BatchAddAlhProduct(sellerId, productId);
			Thread.sleep(5000);
			queryalhproductsBean.setUserId(sellerId);
			queryalhproductsBean.setBrandName("Nike");;
			queryalhproductsBean.setPageIndex(1);
			queryalhproductsBean.setPageSize(100);
			
			queryalhproductsCall.setData(queryalhproductsBean);
			queryalhproductsCall.callService();
			Logger.verifyEquals("200", queryalhproductsCall.getJsonObject().get("Code").getAsString(), "验证Code");
			Logger.verifyNotEquals(-1, queryalhproductsCall.getJsonObject().toString().indexOf(productId), "查询结果是否包含此商品");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_QueryAlhSelectionProducts_005() {
		Logger.start(true, "当买手id不存在的时候，查询失败");
		try {
			queryalhproductsBean.setUserId(1312312388);
			queryalhproductsBean.setPageIndex(1);
			queryalhproductsBean.setPageSize(100);
			
			queryalhproductsCall.setData(queryalhproductsBean);
			queryalhproductsCall.callService();
			Logger.verifyEquals("200", queryalhproductsCall.getJsonObject().get("Code").getAsString(), "验证Code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}